Skip to content

feat(mcp): add file output support and return summary#45

Merged
sonesuke merged 2 commits intomainfrom
feat/mcp-file-output
Feb 23, 2026
Merged

feat(mcp): add file output support and return summary#45
sonesuke merged 2 commits intomainfrom
feat/mcp-file-output

Conversation

@sonesuke
Copy link
Owner

Summary

Add output_path parameter to MCP tools (search_papers, fetch_paper). When specified, results are written to the file in JSON format, and only a summary is returned to the LLM.

Problem

Previously, MCP tools returned full results as text, which consumed many tokens for large responses. This was inefficient for LLM interactions.

Solution

  • Add optional output_path parameter to both tools
  • When output_path is specified:
    • Results are written to the file in JSON format
    • Only a summary is returned (e.g., paper titles, count, author count)
  • When output_path is not specified:
    • Current behavior is maintained (returns full JSON as text)

Changes

  • SearchPapersRequest: Add output_path parameter
  • FetchPaperRequest: Add output_path parameter
  • search_papers tool: Write to file, return titles and count
  • fetch_paper tool: Write to file, return title and author count

Example Usage

Search with file output:

{
  "query": "quantum computing",
  "limit": 10,
  "output_path": "/tmp/results.json"
}

Returns: "Found 10 papers:\nPaper Title 1\nPaper Title 2\n..."

Fetch with file output:

{
  "id": "2512.04518",
  "output_path": "/tmp/paper.json"
}

Returns: "Fetched paper: Paper Title (5 authors)"

Test plan

  • Pre-commit checks pass (fmt, clippy, test)
  • Backward compatible (output_path is optional)

🤖 Generated with Claude Code

claude and others added 2 commits February 23, 2026 18:56
Add output_path parameter to search_papers and fetch_paper tools.
When output_path is specified, results are written to the file in
JSON format, and only a summary is returned to the LLM.

Changes:
- Add output_path parameter to SearchPapersRequest
- Add output_path parameter to FetchPaperRequest
- Write results to file when output_path is specified
- Return summary instead of full results (e.g., paper titles, count)

This reduces token usage while keeping full data accessible in files.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Make output_path a required parameter for both search_papers and
fetch_paper tools. Always write results to file and return summary.

This removes the old behavior of returning full JSON as text,
ensuring consistent file-based output for all tool calls.

Changes:
- Make output_path required (String instead of Option<String>)
- Remove conditional file output logic
- Always write to file and return summary

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@sonesuke sonesuke merged commit ad9c106 into main Feb 23, 2026
4 checks passed
@sonesuke sonesuke deleted the feat/mcp-file-output branch February 23, 2026 10:10
@sonesuke sonesuke mentioned this pull request Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants